<?php
/**
 * @file bg-aa.php	Fixed!
 * @version 0.1
 * @desc 账户管理；存取取出K币、K宝
 * 
 */
$action = $_POST['action'];
$user_id = $_POST['user_id'];
$knum = $_POST['knum'];

$msg = 0; //错误标识
/**
 * 1. 流水操作成功
 * 
 * 444. 数据库连接失败
 * 
 * 410. action为空 或者 错误
 * 411. 用户为空
 * 412. 操作数knum为空
 * 413. 数据库操作失败
 * 414. 数据过程出错
 * 
 */
if (empty($action))
	$msg = 410;
if (empty($user_id))
	$msg = 411;
if (empty($knum))
	$msg = 412;

//登录验证
require_once 'setting.php';
if (validaStatus4AJAX() == 1){
	$msg = 403;
}

if ( $msg == 0){
	
	if ($action == 'kbao-cunru'){
		$sql = "CALL ".DB_NAME_KBAO.".bus_cqKbao({$user_id}, 1, {$knum})";
	}elseif ($action == 'kbao-quchu'){
		$sql = "CALL ".DB_NAME_KBAO.".bus_cqKbao({$user_id}, 2, {$knum})";
	}elseif ($action == 'kbi-cunru'){
		$sql = "CALL ".DB_NAME_KBAO.".bus_cqKbi({$user_id}, 1, {$knum})";
	}elseif ($action == 'kbi-quchu'){
		$sql = "CALL ".DB_NAME_KBAO.".bus_cqKbi({$user_id}, 2, {$knum})";
	}
	Appleseed::executeSQL($sql);
	$re = Appleseed::executeSQL("select @result");
	if ( is_array($re) ){
		$r_id = $re['@result'];
		if ($r_id == '1') $msg = 1;
		else $msg = 414;
	}else $msg = 413;

}//END if $msg 0
echo json_encode($msg);
?>